// Copyright (c) 2010 Thomas Stuefe
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once

using namespace System;

#include "IStatement.h"
#include "ErrorCode.h"

namespace zencat {
namespace sqlite {


	interface class IStatement;

	
    /// <summary>
    /// Interface to an sqlite database.
	/// <para>
    /// A sqlite database is openened or created using <see cref="Sqlite.OpenDatabase"/>.
	/// </para>
    /// </summary>
	public interface class IDatabase
	{
		/// <summary>
		/// Closes the database.
		/// </summary>
		/// <remarks>
		/// This will automatically close all prepared statements and rollback any outstanding transactions.
		/// </remarks>
		void Close();

		/// <summary>
		/// Gets a value indicating whether database is open.
        /// </summary>
		/// <value> True if database is open; False if not. </value>
		property bool IsOpen { 
			bool get(); 
		}

		/// <summary>
		/// Gets a value indicating whether the database was just created. 
        /// </summary>
		/// <value>True if the database was created. False if the database did exist already.</value>
		property bool WasCreated { 
			bool get(); 
		}

		/// <summary>
		/// Gets the file name of the database file.
        /// </summary>
		/// <value> The file name of the database file; null if the database is closed. </value>
		property String^ DatabaseFile { 
			String^ get(); 
		}

		/// <summary>
		/// Gets the sqlite error code associated with the last sqlite operation 
		/// (see also: http://www.sqlite.org/c3ref/errcode.html),
        /// </summary>
		/// <value> the sqlite error code; <see cref="ErrorCode.EC_SQLITE_OK"/> if no error happened. </value>
		/// <remarks>
		/// Multithreading: 
		/// </remarks>
		property ErrorCode LastErrorCode { 
			ErrorCode get(); 
		}

		/// <summary>
		/// Gets the Sqlite error message associated with the last sqlite error
		/// (see also: http://www.sqlite.org/c3ref/c_abort.html ),
        /// null if no error happened.
        /// </summary>
		property String^ LastErrorMessage { 
			String^ get(); 
		}

		/// <summary>
		/// Gets the number of changed rows changed by the most recent sql statement
		/// (see sqlite3_changes() for details)
        /// </summary>
		property int NumberOfChangedRows { 
			int get(); 
		}

		/// <summary>
		/// Gets the rowid for the last inserted row
		/// (see sqlite3_last_insert_rowid() for details)
        /// </summary>
		property __int64 LastInsertRowId { 
			__int64 get(); 
		}

		/// <summary>
		/// Execute sql statement which will not return a result set (a non-query statement like INSERT or UPDATE).
        /// </summary>
		/// <param name="sql">SQL string to execute</param>
		/// <remarks>This is a convenience function; internally a PreparedStatement is created, executed, released.</remarks>
		void ExecuteSql(String^ sql);

		/// <summary>
		/// Creates a Prepared Statment.
        /// </summary>
		/// <param name="sql">The SQL string of the statement</param>
		/// <returns>A prepared (compiled) statement.</returns>
		/// <remarks>This corresponds to the sqlite3_</remarks>
		IStatement^ CreateStatement(String^ sql);
		
		/// <summary>
		/// starts a transaction (commit boundary)
        /// </summary>
		void StartTransaction();

		/// <summary>
		/// commits a transaction
        /// </summary>
		void CommitTransaction();

		/// <summary>
		/// rolls back a transaction
        /// </summary>
		void RollbackTransaction();

		/// <summary>
		/// Gets a value indicating whether Database is in a transaction (commit boundary)
        /// </summary>
		property bool InTransaction { 
			bool get(); 
		}

	};
	// end IDatabase


} // end namespace sqlite

} // end namespace zencat

